package mo.golden;

import java.util.HashMap;
import java.util.Map;

public class L01_04 {

    public boolean canPermutePalindrome(String s) {
        if (s == null || s.length() <= 1) {
            return true;
        }
        Map<Character, Integer> key2count = new HashMap<>();
        for (char c : s.toCharArray()) {
            int count = key2count.getOrDefault(c, 0);
            count++;
            key2count.put(c, count);
        }
        int oddNum = 0;
        for (Map.Entry<Character, Integer> entry : key2count.entrySet()) {
            if (entry.getValue() % 2 != 0) {
                oddNum++;
            }
        }
        return oddNum <= 1;
    }

}
